<template>
  <div v-loading="detailInfoShow">
    <div class="requestAdd">
      <!-- 审核按钮 -->
      <div class="search-button">
        <template v-if="pageType === 'check'">
          <el-button
            class="btn save"
            @click="handleCheckBtn(projectFormRef, 3, '同意')"
            ><el-icon class="icon" color="#fff"> <Tickets /> </el-icon
            >同意</el-button
          >
          <el-button
            class="btn withdraw"
            @click="handleCheckBtn(projectFormRef, 4, '拒绝')"
            ><el-icon class="icon" color="#fff"> <DocumentDelete /> </el-icon
            >拒绝</el-button
          >
          <el-button
            class="btn withdraw"
            @click="handleCheckBtn(projectFormRef, 6, '驳回')"
            ><el-icon class="icon" color="#fff"> <DocumentDelete /> </el-icon
            >驳回</el-button
          >
          <el-button class="btn add" @click="pageType = 'checkEdit'"
            ><el-icon class="icon" color="#fff"> <DocumentDelete /> </el-icon
            >编辑</el-button
          >
        </template>
        <template v-if="pageType !== 'checkEdit'">
          <el-button
            v-if="pageType !== 'check'"
            class="btn submit"
            @click="handleAddSave(requestFormRef, 1)"
            ><el-icon class="icon" color="#fff"> <Tickets /> </el-icon
            >{{ "提交" }}</el-button
          >
          <el-button
            v-if="pageType !== 'check'"
            class="btn save"
            @click="handleAddSave(requestFormRef, 0)"
            ><el-icon class="icon" color="#fff"> <Tickets /> </el-icon
            >存为草稿</el-button
          >
          <el-button class="btn direction" @click="handleBack"
            ><el-icon class="icon" color="#fff"> <Back /> </el-icon
            >返回</el-button
          >
        </template>
      </div>
      <!-- 内容区 -->
      <el-collapse v-model="activeNames">
        <el-form
          :model="requestForm"
          ref="requestFormRef"
          :rules="queryRules"
          label-width="120px"
          v-enterToNext
          :disabled="pageType === 'detail' || pageType === 'check'"
        >
          <!-- 基础信息 -->
          <el-collapse-item name="1" class="transform-down">
            <template #title>
              <span class="circle"></span>
              <span class="collapse-title"
                >{{
                  pageType == "detail" || pageType == "check"
                    ? ""
                    : pageType === "add"
                    ? "新增"
                    : "编辑"
                }}非合同用印</span
              >
            </template>
            <div class="request-info">
              <el-row>
                <!-- <el-col :span="6">
                  <el-form-item label="文件名称：" prop="nonContractSealName">
                    <el-input
                      style="width: 100%"
                      v-model="requestForm.nonContractSealName"
                      maxlength="50"
                      placeholder="请输入"
                    ></el-input>
                  </el-form-item>
                </el-col> -->

                <el-col :span="6">
                  <el-form-item label="申请日期：" prop="applyTime">
                    <el-date-picker
                      v-model="requestForm.applyTime"
                      format="YYYY/MM/DD HH:mm:ss"
                      style="width: 100%"
                      class="search-input"
                      value-format="YYYY-MM-DD HH:mm:ss"
                      type="datetime"
                    />
                  </el-form-item>
                </el-col>

                <el-col :span="6">
                  <el-form-item label="经办人：" prop="userId">
                    <el-select
                      v-model="requestForm.userId"
                      placeholder="请选择"
                      clearable
                      filterable
                      class="search-input"
                      @change="handleUserChange"
                      value-key="userId"
                      placement="bottom-end"
                    >
                      <el-option disabled :value="null">
                        <div class="auto-top">
                          <span class="auto-item">人员姓名</span>
                          <span class="auto-item">联系方式</span>
                          <span class="auto-item">职位</span>
                          <span class="auto-item">部门</span>
                        </div>
                      </el-option>
                      <el-option
                        v-for="dict in userList"
                        :key="dict.userId"
                        :value="dict.userId"
                        :label="dict.nickName"
                      >
                        <div style="display: flex">
                          <div class="auto-item" :title="dict.nickName">
                            {{ dict.nickName }}
                          </div>
                          <div class="auto-item" :title="dict.phonenumber">
                            {{ dict.phonenumber ? dict.phonenumber : "--" }}
                          </div>
                          <div class="auto-item" :title="dict.postName">
                            {{ dict.postName ? dict.postName : "--" }}
                          </div>
                          <div class="auto-item" :title="dict.fullDeptName">
                            {{ dict.fullDeptName ? dict.fullDeptName : "--" }}
                          </div>
                        </div>
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="申请部门：">
                    <el-input
                      disabled
                      v-model="requestForm.deptName"
                      placeholder="自动获取"
                      clearable
                      class="search-input"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="文件编号：" prop="nonContractSealCode">
                    <el-input
                      style="width: 100%"
                      v-model="requestForm.nonContractSealCode"
                      maxlength="50"
                      placeholder="请输入"
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="文件类型：" prop="nonContractType">
                    <el-select
                      v-model="requestForm.nonContractType"
                      placeholder="请选择"
                      clearable
                      style="width: 100%; height: 100%"
                    >
                      <el-option
                        v-for="dict in moduleStatusList"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col
                  :span="6"
                  v-if="[0].includes(requestForm.nonContractType)"
                >
                  <el-form-item label="项目名称：" prop="projectId">
                    <el-select
                      v-model="requestForm.projectId"
                      placeholder="请选择"
                      clearable
                      filterable
                      class="search-input"
                      @change="handleProjectChange"
                    >
                      <el-option key="0" label="" value="" disabled>
                        <span style="float: left; color: #8492a6"
                          >项目编号</span
                        >
                        <span style="margin: 0 80px 0 100px; color: #8492a6"
                          >项目名称</span
                        >
                        <span
                          style="
                            margin: 0 50px 0 0px;
                            color: #8492a6;
                            font-size: 13px;
                          "
                          >项目类别</span
                        >
                        <span
                          style="float: right; color: #8492a6; font-size: 13px"
                          >项目类型</span
                        >
                      </el-option>
                      <el-option
                        v-for="item in projectList"
                        :key="item.projectId"
                        :label="item.projectName"
                        :value="item.projectId"
                      >
                        <span style="float: left; color: #8492a6">{{
                          item.projectCode
                        }}</span>
                        <span
                          style="
                            display: inline-block;
                            width: 125px;
                            margin: 0 10px 0 23px;
                            color: #8492a6;
                            white-space: nowrap;
                            overflow: hidden;
                            text-overflow: ellipsis;
                          "
                          :title="item.projectName"
                          >{{ item.projectName }}</span
                        >
                        <span style="float: right; font-size: 13px">
                          {{ item.projectTypeName }}
                        </span>
                        <span
                          style="
                            float: right;
                            margin: 0 75px 0 0px;
                            font-size: 13px;
                          "
                        >
                          {{ item.projectCategoryName }}
                        </span>
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col
                  :span="6"
                  v-if="[0].includes(requestForm.nonContractType)"
                >
                  <el-form-item label="项目类型：" prop="projectCategoryName">
                    <el-input
                      disabled
                      v-model="requestForm.projectCategoryName"
                      placeholder="自动获取"
                      clearable
                      class="search-input"
                    />
                  </el-form-item>
                </el-col>
                <el-col
                  :span="6"
                  v-if="[0].includes(requestForm.nonContractType)"
                >
                  <el-form-item label="项目编号：" prop="projectCode">
                    <el-input
                      disabled
                      v-model="requestForm.projectCode"
                      placeholder="自动获取"
                      clearable
                      class="search-input"
                    />
                  </el-form-item>
                </el-col>

                <el-col :span="6">
                  <el-form-item label="印章归属：" prop="companyId">
                    <el-select
                      v-model="requestForm.companyId"
                      placeholder="请选择"
                      clearable
                      style="width: 100%; height: 100%"
                    >
                      <el-option
                        v-for="dict in organizationList"
                        :key="dict.companyId"
                        :label="dict.companyName"
                        :value="dict.companyId"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="印章类型：" prop="sealType">
                    <el-select
                      v-model="requestForm.sealType"
                      placeholder="请选择"
                      clearable
                      style="width: 100%; height: 100%"
                    >
                      <el-option
                        v-for="dict in deliveryStatusList"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="收函单位类型：" prop="receivingUnitType">
                    <el-select
                      v-model="requestForm.receivingUnitType"
                      placeholder="请选择"
                      clearable
                      style="width: 100%; height: 100%"
                    >
                      <el-option
                        v-for="dict in receivingUnitList"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label=" 收函单位：" prop="receivingUnit">
                    <el-input
                      style="width: 100%"
                      v-model="requestForm.receivingUnit"
                      maxlength="50"
                      placeholder="请输入"
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="文件用途：" prop="documentUse">
                    <el-input
                      v-model="requestForm.documentUse"
                      placeholder="请输入文件用途"
                      clearable
                      maxlength="50"
                      style="width: 100%; height: 100%"
                      class="search-input"
                    />
                  </el-form-item>
                </el-col>
                <el-col
                  :span="6"
                  v-if="[0].includes(requestForm.nonContractType)"
                >
                  <el-form-item label="运营文件" prop="fileType">
                    <el-select
                      v-model="requestForm.fileType"
                      placeholder="请选择"
                      clearable
                      style="width: 100%; height: 100%"
                    >
                      <el-option
                        v-for="dict in fileTypeList"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col
                  :span="6"
                  v-if="[1].includes(requestForm.nonContractType)"
                >
                  <el-form-item label="行政文件" prop="fileType">
                    <el-select
                      v-model="requestForm.fileType"
                      placeholder="请选择"
                      clearable
                      style="width: 100%; height: 100%"
                    >
                      <el-option
                        v-for="dict in fileTypeList"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col
                  :span="6"
                  v-if="[2].includes(requestForm.nonContractType)"
                >
                  <el-form-item label="财务文件" prop="fileType">
                    <el-select
                      v-model="requestForm.fileType"
                      placeholder="请选择"
                      clearable
                      style="width: 100%; height: 100%"
                    >
                      <el-option
                        v-for="dict in fileTypeList"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="用印份数：" prop="numberOfCopies">
                    <el-input
                      type="Number"
                      v-model="requestForm.numberOfCopies"
                      placeholder="请输入"
                      clearable
                      :max="99"
                      class="search-input"
                    >
                      <template #append>份</template>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="是否归档：" prop="archive">
                    <el-radio-group v-model="requestForm.archive">
                      <el-radio :label="1">是，需要归档</el-radio>
                      <el-radio :label="0">否，无需归档</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
                <el-col :span="6" v-if="[1].includes(requestForm.archive)">
                  <el-form-item label="应归档份数：" prop="pigeonholeNumber">
                    <el-input
                      v-model="requestForm.pigeonholeNumber"
                      type="Number"
                      placeholder="请输入"
                      clearable
                      :max="99"
                      class="search-input"
                    >
                      <template #append>份</template></el-input
                    >
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="6">
                  <el-form-item label="用印申请：" prop="contractAccessory">
                    <Upload
                      :fileList="requestForm.contractAccessory"
                      :isFull="true"
                      :limit="10"
                      limitation="ciculation"
                      :showButton="true"
                      @success="(result) => uploadSuccess(result)"
                      @deleteFile="(result) => uploadRemove(result)"
                      :isCanDelete="
                        pageType == 'detail' || pageType == 'check'
                          ? false
                          : true
                      "
                      :disabled="pageType == 'detail' || pageType == 'check'"
                    />
                    <!-- accept=".jpg,.png" -->
                  </el-form-item>
                </el-col>
              </el-row>
              <div class="searchdon" v-if="pageType == 'checkEdit'">
                <el-button
                  class="btn submit"
                  @click="auditAddSave(requestFormRef, 1)"
                  ><el-icon class="icon" color="#fff"> <Tickets /> </el-icon
                  >{{ "保存" }}</el-button
                >
              </div>
            </div>
          </el-collapse-item>
        </el-form>
      </el-collapse>
    </div>
    <!-- 归档默认0 弹窗 -->
    <el-dialog
      :title="title"
      v-model="auditDialogShow"
      width="600px"
      append-to-body
    >
      <el-form-item label="审核备注：" label-width="90">
        <el-input
          style="width: 100%"
          v-model="auditRemark"
          placeholder=""
          type="textarea"
          maxlength="2000"
          clearable
        />
      </el-form-item>
      <template #footer>
        <div class="dialog-footer">
          <el-button
            style="color: #fff; background-color: rgba(67, 207, 124, 1)"
            v-if="auditResult == 3"
            @click="saveCheck()"
            v-loading="loadingCheck"
            >同意</el-button
          >
          <el-button
            style="color: #fff; background-color: rgba(245, 108, 108, 1)"
            v-if="auditResult == 4"
            @click="saveCheck()"
            v-loading="loadingCheck"
            >拒绝</el-button
          >
          <el-button
            style="color: #fff; background-color: rgba(245, 108, 108, 1)"
            v-if="auditResult == 6"
            @click="saveCheck()"
            v-loading="loadingCheck"
          >
            驳回</el-button
          >
          <el-button style="background-color: #fff" @click="closeAudit()"
            >取 消</el-button
          >
        </div>
      </template>
    </el-dialog>
    <!-- 归档1 提交申请人 弹窗 -->
    <el-dialog
      :title="auditDialog1Showtitle"
      v-model="auditDialog1Show"
      width="1000px"
      append-to-body
    >
      <Subapplicant
        v-if="auditDialog1Show"
        @closeauditDialog1="closeauditDialog1"
        @handleBack="handleBack"
        :requestForm="requestForm"
      ></Subapplicant>
    </el-dialog>
    <!-- 归档2 合同保管员 弹窗 -->
    <el-dialog
      :title="auditDialog2Showtitle"
      v-model="auditDialog2Show"
      width="1000px"
      append-to-body
    >
      <Contractcustodian
        v-if="auditDialog2Show"
        @closeauditDialog2="closeauditDialog2"
        @handleBack="handleBack"
        :requestForm="requestForm"
      ></Contractcustodian>
    </el-dialog>
  </div>
</template>

<script setup>
import useUserStore from "@/store/modules/user";
import Upload from "@/components/Upload/index";
import Subapplicant from "./subapplicant";
import Contractcustodian from "./contractcustodian";
import { getUserListApi } from "@/api/information/customer";
import { getDictsApi } from "@/api/dict";
import { projectListRequest2 } from "@/api/purchase/request";
import {
  nonConSealAdd,
  nonConSealDeatil,
  nonConSealEdit,
  nonConSealCheck,
  nonConSealEditInfo,
} from "@/api/seal/circulation";
import { selectCompanyByList } from "@/api/system/dept";
import { ElMessage, ElMessageBox } from "element-plus";
import dayjs from "dayjs";
const route = useRoute();
const emit = defineEmits([
  // 客户新增组件显隐
  "circulationAddShow",
  // 更新客户新增组件显隐
  "update:circulationAddShow",
  // 刷新父组件表格数据
  "refreshList",
]);
//当前用户信息
const userStore = useUserStore();
const props = defineProps({
  // 操作类型
  pageType: {
    type: String,
    default: "add",
  },
});
// 详情加载效果
const detailInfoShow = ref(false);
// 折叠栏默认展开
const activeNames = ref(["1", "2", "3"]);
// 客户表单引用
const requestFormRef = ref();
// 客户表单数据模板
const requestFormTemplate = {
  // nonContractSealName: "", //文件名称
  nonContractSealCode: "", //文件编号
  applyTime: dayjs(new Date()).format("YYYY-MM-DD HH:mm:ss"), // 申请日期
  userId: null, //经办人
  // deptName: "", // 申请部门
  receivingUnit: "", // 	收函单位
  receivingUnitType: null, //收函单位类型
  projectId: null, //关联项目
  projectCategoryName: "", //项目类型
  projectCode: "", //项目编号
  companyId: null, // 印章归属
  documentUse: "", // 	文件用途
  fileType: null, // 	运营文件|| 行政文件||财务文件
  sealType: null, // 	印章类型
  numberOfCopies: "", // 用印份数
  pigeonholeNumber: "", // 应归档份数
  contractAccessory: [], // 用印申请文件
  nonContractType: null, //模块类型(0:运营用印,1:行政用印,2:财务用印,3:研发用印)
  archive: 1,
  type: 0, //按钮类型0：保存；1；提交
};
const data = reactive({
  // 客户表单
  requestForm: JSON.parse(JSON.stringify(requestFormTemplate)),
  // 客户表单校验规则
  queryRules: {
    applyTime: [
      { required: true, message: "请选择申请日期", trigger: "change" },
    ],
    userId: [{ required: true, message: "请选择经办人", trigger: "change" }],
    companyId: [
      { required: true, message: "请选择印章归属", trigger: "change" },
    ],
    archive: [{ required: true, message: "请选择", trigger: "change" }],
    projectId: [
      { required: true, message: "请选择项目名称", trigger: "change" },
    ],
    nonContractType: [
      { required: true, message: "请选择文件类型", trigger: "change" },
    ],
    fileType: [{ required: true, message: "请选择", trigger: "change" }],
    sealType: [
      { required: true, message: "请选择印章类型", trigger: "change" },
    ],
    // nonContractSealName: [
    //   { required: true, message: "请输入文件名称", trigger: "blur" },
    // ],
    nonContractSealCode: [
      { required: true, message: "请输入文件编号", trigger: "blur" },
    ],
    receivingUnit: [
      { required: true, message: "请输入收函单位", trigger: "blur" },
    ],
    receivingUnitType: [
      { required: true, message: "请选择收函单位类型", trigger: "change" },
    ],
    numberOfCopies: [
      { required: true, message: "请输入用印份数", trigger: "blur" },
      {
        validator: (rule, value, callback) => {
          if (value < 1 || value > 99) {
            callback(new Error("用印份数为0到99之间的整数"));
          } else {
            callback();
          }
        },
        trigger: "blur",
      },
    ],
    documentUse: [
      { required: true, message: "请输入文件用途", trigger: "blur" },
    ],
    pigeonholeNumber: [
      { required: true, message: "请输入应归档份数", trigger: "blur" },
      {
        validator: (rule, value, callback) => {
          if (value < 1 || value > 99) {
            callback(new Error("应归档份数为0到99之间的整数"));
          } else {
            callback();
          }
        },
        trigger: "blur",
      },
    ],
    contractAccessory: [
      { required: true, message: "请上传附件", trigger: "change" },
    ],
  },
  // 用户列表
  userList: [],
  auditRemark: "", //审核备注
  auditResult: null, //审核类型
  applyId: null, //当前数据id
  endFlag: 0,
});
const {
  requestForm,
  queryRules,
  userList,
  auditRemark,
  auditResult,
  applyId,
  endFlag,
} = toRefs(data);
// 项目类型列表
// const kindList = ref([]);
// 项目名称列表
const projectList = ref([]);
// 组织列表
const organizationList = ref([]);
//文件类型列表
const fileTypeList = ref([]);
//印章类型列表
const deliveryStatusList = ref([]);
//收函单位类型列表
const receivingUnitList = ref([]);
//文件类型列表
const moduleStatusList = ref([]);
const loadingCheck = ref(false);
// 选择审核
const auditDialogShow = ref(false);
let auditDialog1Show = ref(false);
let auditDialog1Showtitle = ref("");
let auditDialog2Show = ref(false);
let auditDialog2Showtitle = ref("");
const pageType = ref(props.pageType);
/**
 * @description: 处理人员选择
 * @param {Number} value 选择值
 */
const handleUserChange = (value) => {
  if (value) {
    const selectUser = userList.value.find((item) => item.userId === value);
    if (selectUser) {
      requestForm.value.deptName = selectUser.deptName;
    }
  } else {
    requestForm.value.deptName = "";
  }
};
/**
 * @description: 文件上传成功处理
 * @param {Object} response 文件信息
 */
function uploadSuccess(response) {
  requestForm.value.contractAccessory.push({ ...response, businessType: 30 });
}

/**
 * @description: 删除文件
 * @param {Number} index 当前文件索引
 */
function uploadRemove(index) {
  requestForm.value.contractAccessory.splice(index, 1);
}
/**
 * @description: 处理详情信息
 * @param {Number} id
 */
const handleDetailInfo = async (id) => {
  try {
    detailInfoShow.value = true;
    const res = await nonConSealDeatil({ nonContractSealId: id });
    if (res.code == 200) {
      requestForm.value = {
        ...res.data,
      };
      // 存在为null无法push场景
      if (!requestForm.value.contractAccessory) {
        requestForm.value.contractAccessory = [];
      }
    }
    detailInfoShow.value = false;
  } catch (error) {
    detailInfoShow.value = false;
  }
};
/**
 * @description: 保存
 * @param {Object} requestFormRef 客户表单引用
 */
const handleAddSave = async (requestFormRef, type) => {
  if (!requestFormRef) return;
  await requestFormRef.validate(async (valid, fields) => {
    if (valid) {
      ElMessageBox.confirm(
        "确定" + (type == 0 ? "存为草稿" : "提交") + "吗？",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
          confirmButtonClass: "confirmBtnClass",
          cancelButtonClass: "cancelBtnClass",
        }
      )
        .then(async () => {
          requestForm.value.type = type;
          let res;
          // console.log("提交", requestForm.value);
          if (props.pageType === "add") {
            // 新增客户
            res = await nonConSealAdd(requestForm.value);
          } else {
            // 编辑客户
            res = await nonConSealEdit(requestForm.value);
          }
          if (res.code === 200) {
            emit("update:circulationAddShow", false);
            emit("refreshList", false);
            ElMessage.success(res.msg);
            requestForm.value = JSON.parse(JSON.stringify(requestFormTemplate));
          } else {
            ElMessage.error(res.msg);
          }
        })
        .catch(() => {});
    }
  });
};
/**
 * @description: 审核页面编辑
 * @param {Object} requestFormRef 客户表单引用
 */
const auditAddSave = async (requestFormRef, type) => {
  if (!requestFormRef) return;
  await requestFormRef.validate(async (valid, fields) => {
    if (valid) {
      ElMessageBox.confirm("确定保存吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        confirmButtonClass: "confirmBtnClass",
        cancelButtonClass: "cancelBtnClass",
      })
        .then(async () => {
          requestForm.value.type = type;
          // 审核编辑客户
          const res = await nonConSealEditInfo(requestForm.value);
          if (res.code === 200) {
            pageType.value = "check";
            ElMessage.success(res.msg);
          } else {
            ElMessage.error(res.msg);
          }
        })
        .catch(() => {});
    }
  });
};

/**
 * @description: 审核页面同意
 */
const handleCheckBtn = (requestFormRef, type, title) => {
  if (type == 3) {
    switch (requestForm.value.nextAudit.flowIntype) {
      case "0":
        auditRemark.value = "同意";
        auditResult.value = type;
        applyId.value = requestForm.value.nonContractSealId;
        auditDialogShow.value = true;
        loadingCheck.value = false;
        break;
      case "1":
        //提交申请人
        auditDialog1Show.value = true;
        auditDialog1Showtitle.value = "资料归档";
        break;
      case "2":
        //合同保管人
        auditDialog2Show.value = true;
        auditDialog2Showtitle.value = "资料归档";
        break;

      default:
        break;
    }
  } else {
    auditRemark.value = "";
    auditResult.value = type;
    applyId.value = requestForm.value.nonContractSealId;
    auditDialogShow.value = true;
    loadingCheck.value = false;
  }
};
const saveCheck = async () => {
  if (auditRemark.value === null || auditRemark.value === "") {
    ElMessage.error("审核备注不能为空");
    return;
  }
  try {
    loadingCheck.value = true;
    requestForm.value.auditRemark = auditRemark.value;
    let params = {
      auditRemark: auditRemark.value,
      nonContractSealId: requestForm.value.nonContractSealId,
      checkStatus: auditResult.value,
      // nonContractType: 0, //模块类型(0:运营用印,1:行政用印,2:财务用印,3:研发用印)
    };
    const res = await nonConSealCheck(params);
    auditDialogShow.value = false;
    if (res.code === 200) {
      ElMessage.success(res.msg);
    } else {
      ElMessage.error(res.msg);
      return;
    }
    loadingCheck.value = false;
    emit("update:circulationAddShow", false);
    emit("refreshList", false);
  } catch (error) {
    loadingCheck.value = false;
  }
  ElMessage.error(error);
};

const closeAudit = () => {
  auditRemark.value = "";
  auditResult.value = null;
  applyId.value = null;
  auditDialogShow.value = false;
};

const closeauditDialog1 = () => {
  auditDialog1Show.value = false;
};

const closeauditDialog2 = () => {
  auditDialog2Show.value = false;
};
/**
 * @description: 处理项目选择
 * @param {Number} value 选择值
 */
const handleProjectChange = (value) => {
  if (value) {
    const selectedProject = projectList.value.find(
      (item) => item.projectId === value
    );
    if (selectedProject) {
      requestForm.value.projectCategoryName =
        selectedProject.projectCategoryName;
      requestForm.value.projectCode = selectedProject.projectCode;
    }
  } else {
    requestForm.value.projectCategoryName = "";
    requestForm.value.projectCode = "";
  }
};
/**
 * @description: 返回
 */
const handleBack = () => {
  if (props.pageType === "detail" || props.pageType === "check") {
    emit("update:circulationAddShow", false);
    requestForm.value = JSON.parse(JSON.stringify(requestFormTemplate));
  } else {
    ElMessageBox.confirm("确定返回上一级吗?以上数据未保存将会丢失!", "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
      confirmButtonClass: "confirmBtnClass",
      cancelButtonClass: "cancelBtnClass",
    })
      .then(async () => {
        emit("update:circulationAddShow", false);
        requestForm.value = JSON.parse(JSON.stringify(requestFormTemplate));
      })
      .catch(() => {});
  }
};

/**
 * @description: 获取字典
 */
async function getDicts() {
  await getUserListApi({}).then((res) => {
    if (res.length > 0) {
      userList.value = res;
    }
  });
  // 项目列表
  await projectListRequest2({}).then((res) => {
    if (res) {
      projectList.value = res;
    }
  });
  //组织名称
  // await getDictsApi("erp_party_units").then((res) => {
  //   if (res.code === 200) {
  //     organizationList.value = res.data;
  //   }
  // });
  await selectCompanyByList().then((res) => {
    if (res.length > 0) {
      organizationList.value = res;
    }
  });
  //印章类型
  await getDictsApi("erp_seal_type").then((res) => {
    if (res.code === 200) {
      deliveryStatusList.value = res.data;
    }
  });
  //文件类型
  await getDictsApi("erp_operate_file_type").then((res) => {
    if (res.code === 200) {
      fileTypeList.value = res.data;
    }
  });
  //收函单位类型
  await getDictsApi("erp_receiving_unit_type").then((res) => {
    if (res.code === 200) {
      receivingUnitList.value = res.data;
    }
  });
  //模块类型
  await getDictsApi("erp_non_contract_type").then((res) => {
    if (res.code === 200) {
      moduleStatusList.value = res.data;
    }
  });
}
onMounted(() => {
  getDicts();
  if (props.pageType === "add") {
    requestForm.value.userId = userStore.id;
    requestForm.value.deptName = userStore.deptName;
  }
});
defineExpose({
  handleDetailInfo,
});
</script>

<style lang="scss" scoped>
.requestAdd {
  padding: 20px 20px;
  width: 100%;
  height: 100%;
  .request-info {
    padding: 20px 20px 5px 20px;
    background-color: #f0f0f0;
    margin: 10px 0;
    .searchdon {
      display: flex;
      justify-content: flex-end;
      margin-bottom: 2%;
      .btn.submit {
        color: #fff;
        background: rgba(0, 124, 239, 1);
        &:hover {
          background: rgba(47, 148, 243, 0.85);
        }
      }
    }
  }

  .contact-info {
    padding-top: 20px;
  }

  :deep(.el-table) {
    th.el-table__cell {
      background: #f8f8f8 !important;
    }
  }

  :deep(.el-date-editor.el-input, .el-date-editor.el-input__wrapper) {
    width: 268px !important;
    height: 34px !important;
  }

  .search-input {
    width: 268px;
    height: 34px;
  }

  .image-content {
    width: 100%;
    line-height: 0px;
    overflow: auto;
  }
}

.auto-top {
  width: 100%;
  position: absolute;
  top: 0px;
  display: flex;
  font-weight: bold;
}

.auto-item {
  width: 125px;
  text-align: left;
  white-space: nowrap;
  /* 禁止换行 */
  overflow: hidden;
  /* 隐藏超出部分 */
  text-overflow: ellipsis;
  /* 使用省略号表示超出部分 */
}

.el-autocomplete .el-autocomplete-suggestion {
  max-height: 200px;
  /* 设置最大高度 */
  overflow-y: auto;
  /* 超出高度时显示滚动条 */
}
:deep(.el-form-item--default) {
  margin-bottom: 22px;
}
:deep(.el-form-item--default .el-form-item__error) {
  padding-top: 5px;
}
:deep(.el-form-item--default) {
  margin-bottom: 22px;
}
:deep(.el-form-item--default .el-form-item__error) {
  padding-top: 5px;
}
</style>
